package boot

import (
	"chrent.com/ServiceManage/controller"
	"github.com/gin-gonic/gin"
	"os"
)

func Routes() {
	authm := AuthMiddle()
	e.Use(NewCors())
	e.POST("/api/login", authm.LoginHandler)
	e.POST("/api/test", func(ctx *gin.Context) {
		rtnmap := map[string]any{}

		rtnmap["envhome"] = os.Getenv("HOME")
		rtnmap["gopath"] = os.Getenv("GOPATH")
		ctx.JSON(200, rtnmap)
	})
	e.Any("/", func(ctx *gin.Context) {
		//跳转到"/www"
		ctx.Redirect(301, "/www")
	})
	logined := e.Group("/api")
	logined.GET("/refresh_token", authm.RefreshHandler)
	logined.Use(authm.MiddlewareFunc())
	{
		logined.Any("/admin_info", func(context *gin.Context) {
			context.JSON(200, gin.H{})
			return
		})
		logined.GET("/list", controller.List)
		logined.POST("/add", controller.Add)
		logined.Any("/edit/:id", controller.Edit)
		logined.Any("/start/:id", controller.Start)
		logined.Any("/stop/:id", controller.Stop)
		logined.Any("/restart/:id", controller.Restart)
		logined.Any("/del/:id", controller.Del)
		logined.POST("/update", controller.Update)
		logined.POST("/userinfo", controller.UserInfo)
		logined.POST("/userchange", controller.UserChange)
		logined.POST("/upload", controller.Upgrade)
		logined.GET("log/:id", controller.Log)
		logined.GET("/reload_status", controller.ReloadStatus)
	}
	e.POST("/api/update_by_id", controller.UpgradeFromCurl)
}
